#ifndef __IOStream__
#define __IOStream__
          
#include "neiderra/core/Base.h"
#include <string>

using namespace neiderra::core;

namespace neiderra { 
	namespace core { 
		// Streams interface
		class iStream: public Base {
		public:
			iStream(Core* core_): Base(core_) {}
			virtual ~iStream(){}

			virtual bool open(const char*) =0;
			virtual void close() =0;
		};

		enum SeekType {stBegin, stEnd, stCurrent};

		//! Input stream interface
		class iInputStream: public iStream {
		public:
			iInputStream(Core* core_): iStream(core_) {}
			virtual ~iInputStream(){}

			virtual bool open(const char* filename)=0;
			virtual bool reopen()=0;
			virtual void close() =0;
			virtual int size() =0;
			virtual const char* sourceName() =0;

			virtual int seek(long n, SeekType) =0;
			virtual long pos()=0;

			virtual int	read(char* buf, int n) =0;
		};

		//! Output stream interface
		class iOutputStream: public iStream {
		public:
			iOutputStream(Core* core_): iStream(core_) {}
			virtual ~iOutputStream(){}

			virtual bool open(const char* filename) =0;
			virtual void close() =0;

			virtual int write(const char* buf, int n) =0;
			virtual int write(const char* buf) =0;
			virtual int writeln(const char* buf) =0;
			virtual int writeln(const std::string&) =0;

			virtual const char* sourceName()=0; 
		};

		class iStringStream : public iInputStream {
		public:
			iStringStream(Core* core): iInputStream(core) 
			{
				_pos = 0;
			}
			virtual ~iStringStream() {}

			virtual bool open(const char* str)=0;
			virtual void close() {}
			virtual int size();
			virtual const char* sourceName() { return "string"; }
			virtual int seek(long n, SeekType);
			virtual long pos();
			virtual int read(char* buf, int n);
		protected:
			std::string _str;
			int _pos;
		};
	}
}

#endif 
